﻿@using System.Collections.Generic
@using System.Drawing
@using System.Linq
@using MrCMS.Entities.Documents.Media
@using MrCMS.Helpers
@using MrCMS.Media
@using MrCMS.Web.Areas.Admin.ACL
@using MrCMS.Website
@model MrCMS.Entities.Documents.Media.MediaCategory
@{
    Html.IncludeScript("~/Areas/Admin/Content/Scripts/mrcms/media-uploader.js");
    Html.IncludeScript("~/Areas/Admin/Content/Scripts/mrcms/media-category.js");
    Html.IncludeScript("~/Areas/Admin/Content/Scripts/mrcms/media.js");
    var files = ViewData["files"] as IList<MediaFile> ?? new List<MediaFile>();
    var folders = ViewData["folders"] as IList<MediaCategory> ?? new List<MediaCategory>();
    bool canAccessMediaToolsCut = CurrentRequestData.CurrentUser.CanAccess<MediaToolsACL>(MediaToolsACL.Cut);
    bool canAccessMediaToolsDelete = CurrentRequestData.CurrentUser.CanAccess<MediaToolsACL>(MediaToolsACL.Delete); 
}

<div class="margin-bottom-20">
    @{ Html.RenderAction("Upload", "MediaCategory", new { category = Model }); }
    <div class="clearfix"></div>
</div>

@if (Model != null)
{
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "MediaCategory")">@Resource("Admin Media", "Media")</a></li>
        @foreach (var folder in Model.BreadCrumbs.Reverse())
        {
            <li><a href="@Url.Action("Show", "MediaCategory", new{Id = folder.Id})">@folder.Name</a></li>
        }
    </ol>
}
@if (canAccessMediaToolsCut || canAccessMediaToolsDelete)
{
    <span class="btn-group margin-bottom-20" id="file-tools">
        @{
    if (canAccessMediaToolsCut)
    {
        <button id="cut-files" class="btn btn-default" disabled>@Resource("Cut")</button>
    }
    <button id="paste-files" class="btn btn-default" disabled>@Resource("Paste")</button>
    if (canAccessMediaToolsDelete)
    {
        <button id="delete-files" class="btn btn-default" disabled>@Resource("Delete")</button>
    }
    <button id="clear-files" class="btn btn-default">@Resource("Clear")</button>
        }
    </span>
}

<div class="clearfix"></div>
<div id="folder-container">

    @if (folders.Any())
    {
        foreach (var folder in folders.OrderBy(x => x.DisplayOrder))
        {
            <div class="folder" data-id="folder-@folder.Id" data-url="@Url.Action("Show", "MediaCategory", new{id = folder.Id})" title="@folder.Name">
                <i class="glyphicon glyphicon-folder-open">&nbsp;</i> @folder.Name.TruncateString(28)
            </div>
        }
        <div class="clearfix"></div>
    }
    <div id="file-list" data-file-list="true" data-category-id="@(Model==null ? (int?)null : Model.Id)">
        @if (files.Any())
        {
            foreach (var file in files)
            {
                <div class="file" data-id="file-@file.Id" data-type="file" data-url="@Url.Action("Edit", "File", new { Id = file.Id })">
                    <div class="file-preview">
                        <a title="@file.FileName">
                            @if (file.IsImage)
                            {
                                @Html.RenderImage(file.FileUrl, new Size(100, 100))
                            }
                            else
                            {
                                <i class="@file.FileExtension.GetIconClass()"> </i>
                            }
                        </a>
                    </div>
                    <div class="file-link">
                        @Html.Link(file.FileName, file.FileUrl)
                    </div>
                </div>
            }
            <div class="clearfix"> </div>

        }
        else
        {
            @Html.InfoBlock("", Resource("Admin Media No Files Message", "There are no files here yet - why not upload some?"))
        }
    </div>
    <div class="clearfix"> </div>

</div>
